package com.stone.front.dish.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.stone.back.dish.entity.BfCombo;
import com.stone.back.dish.entity.BfComboDish;
import com.stone.back.dish.entity.BfDish;
import com.stone.back.dish.entity.BfWeekmenuCombo;
import com.stone.base.controller.BaseController;
import com.stone.front.dish.service.IWaresFrontService;

/**
 * 商品管理
 * @author Stone P
 *
 */
@Controller
@RequestMapping("/waresFrontCtl")
public class WaresFrontController extends BaseController {
	@Autowired
	private IWaresFrontService waresFrontService;
	
	/**
	 * 查询个人订餐信息
	 * @param dish	菜品信息
	 * @return
	 * @throws IOException  
	 */
	@RequestMapping("/menuInfo")
    public ModelAndView selectMenuInfo(HttpServletRequest request) throws IOException {
		ModelAndView mv = new ModelAndView("/front/menu");
		//获取周菜单
		List<BfWeekmenuCombo> weekComboList = waresFrontService.selectWeekCombo();
		for (BfWeekmenuCombo weekmenuCombo : weekComboList) {
			List<BfComboDish> comboDishList = waresFrontService.selectComboDish(weekmenuCombo.getComboid());
			weekmenuCombo.setDishList(comboDishList);
		}
		mv.addObject("weekComboList", weekComboList);
//		//获取当天套餐信息
//		BfWeekmenuCombo weekmenuCombo = waresFrontService.selectTodayCombo();
//		List<BfComboDish> comboDishList = new ArrayList<BfComboDish>();
//		if(null != weekmenuCombo) {
//			//今日有套餐，获取套餐菜品信息
//			comboDishList = waresFrontService.selectComboDish(weekmenuCombo.getComboid());
//		}
//		mv.addObject("weekmenuCombo", weekmenuCombo);
//		mv.addObject("comboDishList", comboDishList);
		return mv;
	}
	
	/**
	 * 查询商务订餐信息
	 * @param dish	菜品信息
	 * @return
	 * @throws IOException  
	 */
	@RequestMapping("/businessMenuInfo")
    public ModelAndView selectBusinessMenuInfo(HttpServletRequest request) throws IOException {
		ModelAndView mv = new ModelAndView("/front/businessmenu");
		//多人套餐信息和详情(52：五人，53：十人，54十五人)
		BfCombo fiveCombo = this.waresFrontService.selectComboById(52);
		List<BfComboDish> fiveComboDishList = waresFrontService.selectComboDish(fiveCombo.getComboid());
		BfCombo tenCombo = this.waresFrontService.selectComboById(53);
		List<BfComboDish> tenComboDishList = waresFrontService.selectComboDish(tenCombo.getComboid());
		BfCombo fifteenCombo = this.waresFrontService.selectComboById(54);
		List<BfComboDish> fifteenComboDishList = waresFrontService.selectComboDish(fifteenCombo.getComboid());
		//其他商品列表
		List<BfDish> breadList = this.waresFrontService.selectDishByType(6);
		List<BfDish> juiceList = this.waresFrontService.selectDishByType(7);
		List<BfDish> coffeeList = this.waresFrontService.selectDishByType(8);
		List<BfDish> saladList = this.waresFrontService.selectDishByType(9);
		mv.addObject("fiveCombo", fiveCombo);
		mv.addObject("fiveComboDishList", fiveComboDishList);
		mv.addObject("tenCombo", tenCombo);
		mv.addObject("tenComboDishList", tenComboDishList);
		mv.addObject("fifteenCombo", fifteenCombo);
		mv.addObject("fifteenComboDishList", fifteenComboDishList);
		mv.addObject("breadList", breadList);
		mv.addObject("juiceList", juiceList);
		mv.addObject("coffeeList", coffeeList);
		mv.addObject("saladList", saladList);
		return mv;
	}
	
	/**
	 * 查询商品信息
	 * @param typeId	类型Id
	 * @param request
	 * @return
	 */
	@RequestMapping("/selectDish")
	public ModelAndView selectDishByType(int typeId, HttpServletRequest request) {
		ModelAndView mv = new ModelAndView("/front/wareslist");
		List<BfDish> dishList = this.waresFrontService.selectDishByType(typeId);
		mv.addObject("waresList", dishList);
		mv.addObject("waresType", 1);
		return mv;
	}
	
	/**
	 * 查询套餐信息
	 * @param request
	 * @return
	 */
	@RequestMapping("/selectCombo")
	public ModelAndView selectCombo(HttpServletRequest request) {
		ModelAndView mv = new ModelAndView("/front/wareslist");
		List<BfCombo> comboList = this.waresFrontService.selectCombo();
		mv.addObject("waresList", comboList);
		mv.addObject("waresType", 2);
		return mv;
	}
}
